﻿function listHover(){$(this).addClass('hover').siblings().removeClass('hover');}

$(function()
{	
	$('.hot-goods li').mouseenter(listHover);
	$("#goodslist ul li").hover(function(){							 
		$(".addcart",this).html("加入购物车").css("visibility","visible").stop().animate({bottom:"0px",opacity:"1"}, 300);							 
	},function(){
		$(".addcart",this).stop().animate({bottom: "-37px",opacity:"1"}, 300,function(){$(this).css("visibility","hidden")});
	})
	//
	$("#goodslist ul li .addcart").click(function(){
		var id=$(this).attr("proid");
		var that=this;
			$.ajax(
			{
				type:"post",
				cache:false,
				url:webroot+"cart.asp?act=addcart&id="+id+"&shopnum=1",
				success:function(_)
				{
					var act=_.substring(0,1);
					var info=_.substring(1);
					if(act==0){$.fn.tips({content:info});}else{$(that).html("已成功加入购物车");loadtopcart();get_cartnum();}
										
				}
			});
		
	})
	//userpanel
	if($("#userpanel").length>0)
	{
		$.ajax(
		{
			type:"post",
			cache:false,
			url:webroot+"plug/ajaxlogin.asp",
			data:"url="+location.href,
			success:function(_){$("#userpanel").html(_)}
		});
	}
	//subnav
	var cname="";
	$(".menu li").hover(function(){
		cname=$(this).attr("class");
		if(!cname){$(this).addClass("hover");}
		$("dl",this).show();
	},function(){
		$("dl",this).hide();
		if(!cname){$(this).removeClass("hover");
	}
	});
	loadtopcart();
	//topcate
	$("#topcate").hover(function(){
		$("#cateloading").css("display","block");
		$(this).addClass("hover");
		return false
		
	},function(){
		$("#cateloading").css("display","none");
		$(this).removeClass("hover");
	});
	//
	//计时器
	var stime="";
	$.ajax({type:"post",async:false,url:webroot+"user/ajax.asp",success:function(_){stime=_}})
	var serverTime = stime * 1000; //服务器时间，毫秒数，服务器时间
		var dateTime = new Date();
		var difference = dateTime.getTime() - serverTime; //客户端与服务器时间偏移量
		setInterval(function(){
		  $(".endtime").each(function(){
			var obj = $(this);
			var endTime = new Date(parseInt(obj.attr('value')) * 1000);
			var nowTime = new Date();
			var nMS=endTime.getTime() - nowTime.getTime() + difference;
			var myD=Math.floor(nMS/(1000 * 60 * 60 * 24)); //天
			var myH=Math.floor(nMS/(1000*60*60)) % 24; //小时
			var myM=Math.floor(nMS/(1000*60)) % 60; //分钟
			var myS=Math.floor(nMS/1000) % 60; //秒
			var myMS=Math.floor(nMS/100) % 10; //拆分秒
			if(myD>= 0){
				var str = myD+"天"+myH+"小时"+myM+"分"+myS+"."+myMS+"秒";
			}else{
				var str = "已结束";	
			}
			obj.html(str);
		  });
		}, 100); //每个0.1秒执行一次

	//
})

function setTab(name,cursel,n){
	for(i=1;i<=n;i++){
		var menu=$('#'+name+i);
		var con=$("#con_"+name+"_"+i);
		menu[0].className=i==cursel?"hover":"";
		con[0].style.display=i==cursel?"block":"none";
	}
}

function checksearch(the)
{
	if(the.key.value=="")
	{
		alert("请输入商品名称或编号");
		the.key.focus();
		return false
	}
	if(the.key.value=="请输入商品名称或编号")
	{
		alert("请输入商品名称或编号");
		the.key.focus();
		return false
	}
}

function addfav(id)
{
	var url,data;
	url=webroot+"user/ajax.asp";
	data="act=favorite";
	data+="&t0="+encodeURIComponent(id);
	$.ajax({
	type:"post",
	cache:false,
	url:url,
	data:data,
	success:function(_)
	{
		var act=_.substring(0,1);
		var info=_.substring(1);
		switch(act)
		{
			case "0":
				$.fn.tips({type:"error",content:info});
				break;
			case "1":
				$.fn.tips({type:"error",content:info});
				break;
			case "2":
				$.fn.tips({type:"ok",content:info});
				break;
			default:
				alert(_);
				break;
		}
	}});
	return false
}

function avatar_success()
{
	$.fn.tips({type:"ok",content:"\u5934\u50cf\u4fdd\u5b58\u6210\u529f"});
	setTimeout(function(){location.href='?';},2500)
}

function addNum(t0){var o=$('#'+t0);o.parent().css('position','relative').append($('<span>+1</span>').css({'position':'absolute','left':'0px','top':'-15px','color':'#f00'}).animate({fontSize:80,opacity:0},800,function(){$(this).remove();}))}
